<template>
  <div>
    <el-row>
      <div class="title">查看历史购买记录</div>
      <el-table
        :data="tableData.slice((pagination.currentPage-1) * pagination.rows, pagination.currentPage * pagination.rows)"
      >
        <el-table-column label="商品图">
          <template slot-scope="scope">
            <img :src="scope.row.pictures[0]" class="history-buy-img">
          </template>
        </el-table-column>
        <el-table-column label="商品名" prop="goodName"
        ></el-table-column>
        <el-table-column label="商品价格" prop="price"
        ></el-table-column>
        <el-table-column label="购买数量" prop="amount"
        ></el-table-column>
        <el-table-column label="交易地址" prop="transactionAddress"
        ></el-table-column>
      </el-table>
    </el-row>
    <el-row >
      <el-col :span="24">
        <el-pagination
          id="pagination"
          class="pagination"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="prev, pager, next, jumper"
          :current-page="pagination.currentPage"
          :page-size="pagination.rows"
          :total="tableData.length">
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "CustomHistoryBuy",
  data() {
    return {
      tableData: null,
      page: 1,
      size: 6,
      total: null,
      pagination: {
        currentPage: 1,
        rows: 6,
      }
    }
  },
  methods: {
    getOrderByuser_idX: function () {
      this.$api.user.getOrderByuser_idX({
        userId: sessionStorage.getItem("userId")
      }).then(res => {
        console.log("getHistoryBuy", res);
        if (res.data.code === 200) {
          this.tableData = res.data.data;
        } else {
          this.tableData = [];
        }
      })
    },
    handleSizeChange(val) {
      this.pagination.rows = val;
    },
    handleCurrentChange(val) {
      this.pagination.currentPage = val;
    },
    handList: function () {
      this.pagination.list = this.goodList;
    },
  },
  created() {
    this.getOrderByuser_idX();
  }
}
</script>

<style scoped>
.title {
  font-size: 36px;
  font-weight: bold;
  color: #363636;
  padding-bottom: 30px;
}
.history-buy-img {
  height: 50px;
  width: 50px;
  border-radius: 5px;
}
.pagination {
  float: right;
  padding-right: 100px;
  padding-top: 10px;
}
>>>.el-pagination.is-background .el-pager li:not(.disabled).active {
  background: rgba(176, 224, 230, 1);
}
</style>
